﻿
using NetCourse.Framework.Database;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;

namespace Xmu.Stores.Models
{
    public class User : EntityBase,IUserPrincipal
    {
        #region 字段
        public Guid ID { get; set; } = Guid.NewGuid();
        [Required(ErrorMessage ="username不能为空")]
        [MaxLength(12, ErrorMessage = "username长度应小于20")]
        public string UserName { get; set; } = string.Empty;

        [Required(ErrorMessage = "password不能为空")]
        public string Password { get; set; } = string.Empty;

        [EmailAddress]
        public string? Email { get; set; }

        [Phone]
        public string? PhoneNumber { get; set; }

        // 故意不设置验证长度，留下一个测试错误用例
        public string? StudentId { get;set; }

        public string? Region { get; set; } = string.Empty;
        #endregion

        public override string ToString()
        {
            return JsonSerializer.Serialize(this, new JsonSerializerOptions
            {
                WriteIndented = true // 可选：以缩进格式输出 JSON
            });
        }
    }
}
